/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package attackDetection;
import java.sql.*;
import java.sql.Time;
import java.sql.Timestamp;
/**
 *
 * @author john
 */
public class Plog {
    private int index;
    private int nodeId;
    private int nodeIP;
    private String previousNodeIP;
    private String mode;
    private String type;
    private int packetLength;
    private int packetSequenceNum;
    private int messageSize;
    private int messageSequenceNum;
    private Time timeso;
    // Missing unixtime
    private Timestamp timeStamp;
    // Missing unixtimestamp
    private int vtime;
    private int sourceNodeIP;
    private String psip;
    private int destinationNodeIP;
    private String pdip;
    private int nextHopId;
    private int nextHopIP;
    private String pnhip;
    private int phid;
    private int phip;
    private String pphip;
    private int ttl;
    private int hc;
    private int nonb;
    private int watchdog;

    public Plog(){


    }

    /*
     * The contents of the method belong in the constructor
     */
    public void Init(ResultSet res){
        try {
            setIndex(res.getInt("plogid"));
            setNodeId(res.getInt("nodeid"));
            setNodeIP(res.getInt("nodeip"));
            setMode(res.getString("opmode"));
            setType(res.getString("msgtype"));
            setPacketLength(res.getInt("plength"));
            setPacketSequenceNum(res.getInt("pseqno"));
            setMessageSize(res.getInt("msgsize"));
            setMessageSequenceNum(res.getInt("msgseqno"));
            setTimeso(res.getTime("timeso"));
            // Missing unixtimeso
            setTimeStamp(res.getTimestamp("timestamp"));
            // Missing unixtimestampso
            setVtime(res.getInt("vtime"));
            setSourceNodeIP(res.getInt("sip"));
            setDestinationNodeIP(res.getInt("dip"));
            setNextHopId(res.getInt("nexthopid"));
            setNextHopIP(res.getInt("nexthopip"));
            setPhid(res.getInt("prehopid"));
            setPhip(res.getInt("prehopip"));
            setTtl(res.getInt("ttl"));
            setHc(res.getInt("hopcount"));
            setNonb(res.getInt("nonb"));
            setWatchdog(res.getInt("watcher"));

        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }

    }

    // Utility Function
    public boolean sametimeroute (Plog p){
        boolean temp = false;

        if(getSourceNodeIP() == p.getSip() && getDestinationNodeIP() == p.getDip() && getPacketSequenceNum() == p.getPseqno()
                && getTimeso().equals(p.getTimeso()))
            temp = true;

        return temp;
    }
    
    boolean replayattack (Plog p){
        return true;
    }
    

    @Override
    public String toString(){
        String out = "";
        out += "Index: " + getIndex() + " NodeID: " + getNodeId() + " NodeIP: " + getNodeIP() + "\n";
        out += "Mode: " + getMode() + " Packet Type: " + getType() + " Packet Length: " + getPacketLength();
        out += " Packet Sequence No.: " + getPacketSequenceNum() + "\n";
        out += "Message Size: " + getMessageSize() + " Message Sequence No.: " + getMessageSequenceNum() + "\n";
        out += "Packet sent out from source at " + getTimeso().toString();
        out += "Packet was at this node at " + getTimeStamp().toString();
        out += "Validity time: " + getVtime() + " Source IP: " + getPsip() + " Destination IP: " + getDestinationNodeIP() + "\n";
        out += "Next hop ID: " + getNextHopId() + "Next hop IP: " + getNextHopIP() +"\n";
        out += "Previous hop ID: " + getPhip() + " Previous hop IP: " + getPphip() + "\n";
        out += "TTL: " + getTtl() + " Hop count: " + getHc() + "No of Neighbors: " + getNonb() + "\n";
        return out;
    }

    /**
     * @return the index
     */
    public int getIndex() {
        return index;
    }

    /**
     * @param index the index to set
     */
    public void setIndex(int index) {
        this.index = index;
    }

    /**
     * @return the nodeId
     */
    public int getNodeId() {
        return nodeId;
    }

    /**
     * @param nodeId the nodeId to set
     */
    public void setNodeId(int nodeId) {
        this.nodeId = nodeId;
    }

    /**
     * @return the nodeIP
     */
    public int getNodeIP() {
        return nodeIP;
    }

    /**
     * @param nodeIP the nodeIP to set
     */
    public void setNodeIP(int nodeIP) {
        this.nodeIP = nodeIP;
    }

    /**
     * @return the mode
     */
    public String getMode() {
        return mode;
    }

    /**
     * @param mode the mode to set
     */
    public void setMode(String mode) {
        this.mode = mode;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the plength
     */
    public int getPlength() {
        return getPacketLength();
    }

    /**
     * @param plength the plength to set
     */
    public void setPlength(int plength) {
        this.setPacketLength(plength);
    }

    /**
     * @return the pseqno
     */
    public int getPseqno() {
        return getPacketSequenceNum();
    }

    /**
     * @param pseqno the pseqno to set
     */
    public void setPseqno(int pseqno) {
        this.setPacketSequenceNum(pseqno);
    }

    /**
     * @return the msgsize
     */
    public int getMsgsize() {
        return getMessageSize();
    }

    /**
     * @param msgsize the msgsize to set
     */
    public void setMsgsize(int msgsize) {
        this.setMessageSize(msgsize);
    }

    /**
     * @return the msgseqno
     */
    public int getMsgseqno() {
        return getMessageSequenceNum();
    }

    /**
     * @param msgseqno the msgseqno to set
     */
    public void setMsgseqno(int msgseqno) {
        this.setMessageSequenceNum(msgseqno);
    }

    /**
     * @return the vtime
     */
    public int getVtime() {
        return vtime;
    }

    /**
     * @param vtime the vtime to set
     */
    public void setVtime(int vtime) {
        this.vtime = vtime;
    }

    /**
     * @return the sip
     */
    public int getSip() {
        return getSourceNodeIP();
    }

    /**
     * @param sip the sip to set
     */
    public void setSip(int sip) {
        this.setSourceNodeIP(sip);
    }

    /**
     * @return the psip
     */
    public String getPsip() {
        return psip;
    }

    /**
     * @param psip the psip to set
     */
    public void setPsip(String psip) {
        this.psip = psip;
    }

    /**
     * @return the dip
     */
    public int getDip() {
        return getDestinationNodeIP();
    }

    /**
     * @param dip the dip to set
     */
    public void setDip(int dip) {
        this.setDestinationNodeIP(dip);
    }

    /**
     * @return the pdip
     */
    public String getPdip() {
        return pdip;
    }

    /**
     * @param pdip the pdip to set
     */
    public void setPdip(String pdip) {
        this.pdip = pdip;
    }

    /**
     * @return the nhid
     */
    public int getNhid() {
        return getNextHopId();
    }

    /**
     * @param nhid the nhid to set
     */
    public void setNhid(int nhid) {
        this.setNextHopId(nhid);
    }

    /**
     * @return the nhip
     */
    public int getNhip() {
        return getNextHopIP();
    }

    /**
     * @param nhip the nhip to set
     */
    public void setNhip(int nhip) {
        this.setNextHopIP(nhip);
    }

    /**
     * @return the pnhip
     */
    public String getPnhip() {
        return pnhip;
    }

    /**
     * @param pnhip the pnhip to set
     */
    public void setPnhip(String pnhip) {
        this.pnhip = pnhip;
    }

    /**
     * @return the phid
     */
    public int getPhid() {
        return phid;
    }

    /**
     * @param phid the phid to set
     */
    public void setPhid(int phid) {
        this.phid = phid;
    }

    /**
     * @return the phip
     */
    public int getPhip() {
        return phip;
    }

    /**
     * @param phip the phip to set
     */
    public void setPhip(int phip) {
        this.phip = phip;
    }

    /**
     * @return the pphip
     */
    public String getPphip() {
        return pphip;
    }

    /**
     * @param pphip the pphip to set
     */
    public void setPphip(String pphip) {
        this.pphip = pphip;
    }

    /**
     * @return the ttl
     */
    public int getTtl() {
        return ttl;
    }

    /**
     * @param ttl the ttl to set
     */
    public void setTtl(int ttl) {
        this.ttl = ttl;
    }

    /**
     * @return the hc
     */
    public int getHc() {
        return hc;
    }

    /**
     * @param hc the hc to set
     */
    public void setHc(int hc) {
        this.hc = hc;
    }

    /**
     * @return the nonb
     */
    public int getNonb() {
        return nonb;
    }

    /**
     * @param nonb the nonb to set
     */
    public void setNonb(int nonb) {
        this.nonb = nonb;
    }

    /**
     * @return the watchdog
     */
    public int getWatchdog() {
        return watchdog;
    }

    /**
     * @param watchdog the watchdog to set
     */
    public void setWatchdog(int watchdog) {
        this.watchdog = watchdog;
    }

    /**
     * @return the timeso
     */
    public Time getTimeso() {
        return timeso;
    }

    /**
     * @param timeso the timeso to set
     */
    public void setTimeso(Time timeso) {
        this.timeso = timeso;
    }

    /**
     * @return the timestamp
     */
    public Timestamp getTimestamp() {
        return getTimeStamp();
    }

    /**
     * @param timestamp the timestamp to set
     */
    public void setTimestamp(Timestamp timestamp) {
        this.setTimeStamp(timestamp);
    }

    /**
     * @return the previousNodeIP
     */
    public String getPreviousNodeIP() {
        return previousNodeIP;
    }

    /**
     * @param previousNodeIP the previousNodeIP to set
     */
    public void setPreviousNodeIP(String previousNodeIP) {
        this.previousNodeIP = previousNodeIP;
    }

    /**
     * @return the packetLength
     */
    public int getPacketLength() {
        return packetLength;
    }

    /**
     * @param packetLength the packetLength to set
     */
    public void setPacketLength(int packetLength) {
        this.packetLength = packetLength;
    }

    /**
     * @return the packetSequenceNum
     */
    public int getPacketSequenceNum() {
        return packetSequenceNum;
    }

    /**
     * @param packetSequenceNum the packetSequenceNum to set
     */
    public void setPacketSequenceNum(int packetSequenceNum) {
        this.packetSequenceNum = packetSequenceNum;
    }

    /**
     * @return the messageSize
     */
    public int getMessageSize() {
        return messageSize;
    }

    /**
     * @param messageSize the messageSize to set
     */
    public void setMessageSize(int messageSize) {
        this.messageSize = messageSize;
    }

    /**
     * @return the messageSequenceNum
     */
    public int getMessageSequenceNum() {
        return messageSequenceNum;
    }

    /**
     * @param messageSequenceNum the messageSequenceNum to set
     */
    public void setMessageSequenceNum(int messageSequenceNum) {
        this.messageSequenceNum = messageSequenceNum;
    }

    /**
     * @return the timeStamp
     */
    public Timestamp getTimeStamp() {
        return timeStamp;
    }

    /**
     * @param timeStamp the timeStamp to set
     */
    public void setTimeStamp(Timestamp timeStamp) {
        this.timeStamp = timeStamp;
    }

    /**
     * @return the sourceNodeIP
     */
    public int getSourceNodeIP() {
        return sourceNodeIP;
    }

    /**
     * @param sourceNodeIP the sourceNodeIP to set
     */
    public void setSourceNodeIP(int sourceNodeIP) {
        this.sourceNodeIP = sourceNodeIP;
    }

    /**
     * @return the destinationNodeIP
     */
    public int getDestinationNodeIP() {
        return destinationNodeIP;
    }

    /**
     * @param destinationNodeIP the destinationNodeIP to set
     */
    public void setDestinationNodeIP(int destinationNodeIP) {
        this.destinationNodeIP = destinationNodeIP;
    }

    /**
     * @return the nextHopId
     */
    public int getNextHopId() {
        return nextHopId;
    }

    /**
     * @param nextHopId the nextHopId to set
     */
    public void setNextHopId(int nextHopId) {
        this.nextHopId = nextHopId;
    }

    /**
     * @return the nextHopIP
     */
    public int getNextHopIP() {
        return nextHopIP;
    }

    /**
     * @param nextHopIP the nextHopIP to set
     */
    public void setNextHopIP(int nextHopIP) {
        this.nextHopIP = nextHopIP;
    }

}
